// Learn cc.Class:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html
var util = require("Utils");
var comps = require('ComponentDifine');
var viewDefine = require("ViewDefine");

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        Label_nickname: cc.Label,
        Label_ID: cc.Label,
        isNewPlayer: null,
        isRoomCreater: null,
        roomID: 0,
        numberMark: null,
        otherGiveCard: null,
        isCreaterDismissed: null
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function () {

        var resLoad = [
            comps.radio,
            comps.check];

        App.assets = {};

        for (let i = 0; i < resLoad.length; i++) {
            cc.loader.loadRes(resLoad[i], (err, prefab) => {
                if (err) {
                    cc.error(err);
                    return;
                }
                App.assets[resLoad[i]] = prefab;
                console.log(App.assets[resLoad[i]]);
            });
        }
        // this.isNewPlayer = data.isNewPlayer;
        // this.isRoomCreater = data.isRoomCreater;
        // this.roomID = data.roomID;
        // this.numberMark = data.numberMark;
        // this.otherGiveCard = data.otherGiveCard;
        // this.isCreaterDismissed = data.isCreaterDismissed;
        // if (!cc.h5App) {
        //     cc.director.loadScene("Entrance");
        //     return;
        // }
        //net.connect("ws://172.16.40.234:50250", null)
        //this.Label_nickname.String = "user"
    },

    start() {
        // cc.h5App.ws.connect("ws://neimengh5.xlkaifeng.com:5094",null)
        // playerInfo = cc.find("Canvas/Node_top/Node_playerInfo")
        //var createRoom = cc.find("Canvas/Node_center/Panel_createRoom")
        //this.playerInfo.active = false
        // createRoom.on('touchend', function (event) {
        //     alert("ssss");
        // },this)
        // utils.addClickEvent(this.nodeCreateRoom, this.nodeCreateRoom.node, "MainScene", "onClicked")
        // var info = this.playerInfo.getComponent("NodePlayerInfo")
        // this.playerInfo.node.getChildByName("Label_nickname").getComponent(cc.Label).string = this.roomID;
    },

    onCreateRoom: function (event) {
        util.createView(viewDefine.playsEdit);
    },
    onJoinRoom: function (event) {
        util.createView(viewDefine.joinRoom);
    },
    onMatchRoom: function (event) {
        alert("H5版本暂未开放比赛场");
    },
    onCoinRoom: function (event) {
        alert("H5版本暂未开放金币场");
    },
    onGuild: function (event) {
        alert("H5版本暂未开放俱乐部");
    },
    // update (dt) {},
});
